package packet1;

import java.util.*;
/*
sb
 */

public class cpu {
    public static class service {
        int id;
        int CPUCore;
        int menSize;
        int CPUArch;
        int supportNP;

        public service(int id, int CPUCore, int menSize, int CPUArch, int supportNP) {
            this.id = id;
            this.CPUCore = CPUCore;
            this.menSize = menSize;
            this.CPUArch = CPUArch;
            this.supportNP = supportNP;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        sc.nextLine();
        int sum_cpu[][] = new int[M][5];
        for (int i = 0; i < M; i++) {
            String[] sp = sc.nextLine().split(",");
            sum_cpu[i][0] = Integer.parseInt(sp[0]);
            sum_cpu[i][1] = Integer.parseInt(sp[1]);
            sum_cpu[i][2] = Integer.parseInt(sp[2]);
            sum_cpu[i][3] = Integer.parseInt(sp[3]);
            sum_cpu[i][4] = Integer.parseInt(sp[4]);
        }
        int target[] = new int[6];
        for (int i = 0; i < 6; i++) {
            target[i] = sc.nextInt();
        }
        List<service> list = new ArrayList<>();

        if(target[1] == 1){
            Collections.sort(list,(o1,o2) ->{
               if(o1.CPUCore == o2.CPUCore)
               {
                   if(o1.menSize == o2.menSize)
                   {
                       return o1.id - o2.id;
                   }
                   else
                       return o1.menSize - o2.menSize;
               }
               else
                   return o1.CPUCore - o2.CPUCore;
            });
        }
        else{
            Collections.sort(list,(o1,o2) ->{
                if(o1.menSize == o2.menSize)
                {
                    if(o1.CPUCore == o2.CPUCore)
                    {
                        return o1.id - o2.id;
                    }
                    else
                        return o1.CPUCore - o2.CPUCore;
                }
                else
                    return o1.menSize - o2.menSize;
            });
        }

        for (int i = 0; i < M; i++) {
            if(sum_cpu[i][1] >= target[2] && sum_cpu[i][2] >= target[3] &&(target[4] == 9 || sum_cpu[i][3] == target[4])
                    && (sum_cpu[i][4] == target[5] || target[5] ==2))
            {
                list.add(new service(sum_cpu[i][0],sum_cpu[i][1],sum_cpu[i][2],sum_cpu[i][3],sum_cpu[i][4]));
            }
        }

        int t = Math.min(list.size(),target[0]);
        int re[] = new int[t];
        for (int i = 0; i < t; i++) {
            re[i] = list.get(i).id;
        }
        Arrays.sort(re);
        System.out.print(t);
        for(int p : re)
            System.out.print(" " + p);



//        Map<Integer, Integer> map = new HashMap<>();
//        map.put(1,2);
//        for(Map.Entry<Integer,Integer> entry: map.entrySet()){

//        }
    }
}
/*
4
0,2,200,0,1
1,3,400,0,1
2,3,400,1,0
3,3,300,0,1
3 1 3 200 0 1
 */
